package com.atguigu;


import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/servlet4")
public class servlet4  extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext = getServletContext();
        //1.指向部署目录下面的文件夹,然后获取地址
        String upload = servletContext.getRealPath("upload");
        System.out.println(upload);
        //2.获取项目上下文路径或者资源访问路径
        String contextPath = servletContext.getContextPath();
        System.out.println(contextPath);
        servletContext.setAttribute("key1","value1");
        String attribute = (String) servletContext.getAttribute("key1");
        System.out.println(attribute);
        servletContext.removeAttribute("key1");
        System.out.println(servletContext.getAttribute("key1"));

    }
}
